﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using classInterface;
using classInterface.button;
using classInterface.text;
using System.Reflection;

namespace FormTest
{
    public partial class Form1 : Form
    {
        private delegate void DisplayDataDelegate(Point[] pp);
        public Form1()
        {
            InitializeComponent();
        }

        private UserForm _usrForm;
        private void Form1_Load(object sender, EventArgs e)
        {
            string path = System.Environment.CurrentDirectory;
            //获取类
            var list = ActivatorHelper.GetSubTypes<UserForm>(
                path, "classInterface.**.dll")
                .Where(kv => kv.Value?.Count() > 0 && kv.Value[0] != null)
                .Select(kv => kv.Value.FirstOrDefault())
                .Select(type => ActivatorHelper.Create<UserForm>(type))
                .ToArray();
            comboBox1.Items.AddRange(list);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            _usrForm.ShowName();
            timer1.Enabled = true;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            _usrForm = comboBox1.SelectedItem as UserForm;
            panel1.Controls.Clear();
            _usrForm.cenControl_.Size = new Size(300, 300);
            _usrForm.cenControl_.BackColor = Color.Red;
           
            panel1.Controls.Add(_usrForm.cenControl_);
        }

        private void button1_Click(object sender, EventArgs e)
        {
             
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            var fde = new DisplayDataDelegate(_usrForm.DrawData);
            Point[] p = new Point[10];
            Random r = new Random();
            for (int i = 0; i < 10; i++)
            {

                p[i] = new Point(r.Next(10, 150), r.Next(30, 140));
            }
            BeginInvoke(fde, p);
        }
    }
}
